package com.jokins.admin.vue.user.service.impl;


import com.jokins.admin.vue.user.actioncontext.*;
import com.jokins.admin.vue.user.param.SysUserChangePasswordParam;
import com.jokins.admin.vue.user.param.SysUserInfoParam;
import com.jokins.admin.vue.user.param.SysUserLoginParam;
import com.jokins.admin.vue.user.param.SysUserRegisterPasswordParam;
import com.jokins.admin.vue.user.service.SysUserService;
import com.jokins.admin.vue.user.vo.LoginStatsVo;
import com.jokins.admin.vue.user.vo.SysUserLoginVo;
import com.jokins.admin.vue.user.vo.SysUserVo;
import com.jokins.common.actions.action.ActionContext;
import com.jokins.common.actions.util.ActionDispatcher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 〈〉<br>
 *
 * @author Mr.Wang
 * @create 2024/9/4
 */
@Slf4j
@Service
public class SysUserServiceImpl implements SysUserService {


    /**
     * 登录
     *
     * @param param
     * @return
     */
    @Override
    public SysUserLoginVo sysUserLogin(SysUserLoginParam param) {
        SysUserLoginDoc doc = new SysUserLoginDoc(param);
        ActionDispatcher.execute(doc);
        return (SysUserLoginVo) doc.getResultValue(ActionContext.RESULT_DOC_KEY);
    }

    /**
     * 修改密码
     *
     * @param param
     */
    @Override
    public void sysUserChangePassword(SysUserChangePasswordParam param) {
        SysUserChangePasswordDoc doc = new SysUserChangePasswordDoc(param);
        ActionDispatcher.execute(doc);
        log.info("修改密码成功！");
    }


    /**
     * 注册
     *
     * @param param
     */
    @Override
    public Map<String, String> sysUserRegisterPassword(SysUserRegisterPasswordParam param) {
        SysUserRegisterPasswordDoc doc = new SysUserRegisterPasswordDoc(param);
        ActionDispatcher.execute(doc);
        log.info("注册成功！");
        return (Map<String, String>) doc.getResultValue(ActionContext.RESULT_DOC_KEY);
    }

    /**
     * 重置密码
     *
     * @param id
     */
    @Override
    public String sysUserRePassword(String id) {
        SysUserRePasswordDoc doc = new SysUserRePasswordDoc(id);
        ActionDispatcher.execute(doc);
        return (String) doc.getResultValue(ActionContext.RESULT_DOC_KEY);
    }

    /**
     * 登录统计
     *
     * @return
     */
    @Override
    public List<LoginStatsVo> getLoginStats() {
        return List.of();
    }

    /**
     * 查询用户信息
     *
     * @param param
     * @return
     */
    @Override
    public List<SysUserVo> selectUserInfo(SysUserInfoParam param) {
        GetSysUserDoc doc = new GetSysUserDoc(param);
        ActionDispatcher.execute(doc);
        return (List<SysUserVo>) doc.getResultValue(ActionContext.RESULT_DOC_KEY);
    }
}